Add preview mode for update actions#1945
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
|
@georgeh0 can help take a look! |
georgeh0
left a comment
There was a problem hiding this comment.
Sorry for the late review!
Most parts look good. A few minor comments. Please also merge with latest and resolve conflict. Thanks!
| def test_preview_prints_actions(self) -> None: | ||
| """update --preview should print planned actions without writing.""" | ||
| result = run_cli("update", "./flat_target_app.py", "--preview") | ||
| assert "Preview: planned target actions" in result.stdout |
There was a problem hiding this comment.
Can we also check the specific actions really printed out in the output?
| options.preview, | ||
| preview_collector.clone(), |
There was a problem hiding this comment.
It's possible to combine these two, i.e. everywhere we can use preview_collector.is_some() to determine if it's under preview mode.
We can even consider using Option<PreviewActionCollector<Prof>> to replace the preview: bool field in AppUpdateOptions. The update() API will remain returning a single handle (PreviewCollector is more like a side channel output, so keeping the return value a simple handle is attractive).
Summary
Adds preview mode for update actions in both the Python API and CLI.
With preview enabled, CocoIndex computes the same target actions as a normal update, but does not apply them to real targets and does not commit internal tracking state.
Closes #1890.
API and CLI
Preview is supported in:
App.update(..., preview=True)App.update_blocking(..., preview=True)cocoindex update --previewFor the Python API, preview returns the planned action objects.
For the CLI, preview prints the planned actions.
Implementation
This reuses the existing planning path instead of introducing a separate planner.
In preview mode:
pre_commit(...)sink.apply(...)is skippedThis keeps preview aligned with normal update behavior while remaining read-only.
First pass scope
This first pass supports flat / leaf target actions only.
If a target requires child target providers, preview fails clearly instead of returning partial output.
CLI behavior
Added:
cocoindex update ... --previewTests
Added coverage for:
Validation
Ran locally:
cargo fmt --checkcargo testuv run mypyuv run pytest python/tests/core -quv run pytest python/tests/internal -quv run pytest python/tests/cli/test_cli.py -q